<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
  <head>
    <title>用户管理</title>
    <jsp:include page="header.jsp"></jsp:include>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">人员管理</a>
        <a>
          <cite>用户管理</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
     <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="/admin/userList" method="post" id="listForm">
        <div class="layui-col-md4">
      		<select name="roleName" class="my-select">
      		  <option value="">请选择角色</option>
              <option value="医生">医生</option>
              <option value="销售员">销售员</option>
              <option value="店员">店员</option>
              <option value="管理员">管理员</option>
        	 </select>
    	</div>
    	<div class="layui-col-md4">
      	  <input type="text" name="username"  placeholder="请输入用户名称" autocomplete="off" class="layui-input">
          <input type="hidden" name="start" id="hh"/> 
          <button class="layui-btn"><i class="layui-icon">&#xe615;</i></button>
    	</div>
        </form>
      </div>
      <xblock>
        <span class="x-right" style="line-height:40px">共有数据：${total} 页</span>
      </xblock>
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>用户名</th>
            <th>微信名称</th>
            <th>图像</th>
            <th>电话号码</th>
            <th>角色名称</th>
            <th>真实姓名</th>
            <th>生成图片</th>
            <th>操作</th></tr>
        </thead>
        <tbody>
        <c:if test="${not empty list}">
      	<c:forEach var="app" items="${list}" varStatus="st">
          <tr>
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
	            </td>
	            <td>${st.index +1}</td>
	            <td>${app.username}</td>
	            <td>${app.weName}</td>
	            <td><img src="${pageContext.request.contextPath }${app.picUrl}" alt="" width="70" height="50" /></td>
	            <td>${app.telephone}</td>
	            <td>${app.roleName}</td>
	            <td>${app.realName}</td>
	            <td><c:if test="${app.roleName eq '医生'}"><button onclick="myClick('${app.id}')" class="layui-btn">二维码</button></c:if></td>
	            <td class="td-manage">
	              <a title="编辑"  onclick="x_admin_show('编辑','/admin/toAdd?id=${app.id}',600,400)" href="javascript:;">
	                <i class="layui-icon">&#xe642;</i>
	              </a>
	              <a title="删除" onclick="member_del(this,'${app.id}')" href="javascript:;">
	                <i class="layui-icon">&#xe640;</i>
	              </a>
	            </td>
          </tr>
          </c:forEach>
	      </c:if>
        </tbody>
      </table>
      <div class="page">
        <div>
          <a class="my-first" href="javascript:;">
          	首页</a>
          <a class="prev" href="javascript:;">上一页</a>
          <a class="next" href="javascript:;">下一页</a>
          <a class="my-last" href="javascript:;">末页</a>
        </div>
      </div>

    </div>
    <script>
      /*用户-删除*/
      function member_del(obj,id){
    	  layer.confirm('您确定删除这条记录吗？', {
    		  btn: ['确实','取消'] //按钮
    		}, function(){
    			$.get("/admin/userDel?id="+id, function(data){
    				if("ok"==data){
    					layer.msg('删除成功!', {icon: 1});
    					location.reload();
    				}else{
    					layer.msg('删除失败!', {icon: 1});
    				}
    				  //alert("Data Loaded: " + data);
    				});
    		}, function(){
    		  layer.msg('您取消了操作!', {
    		    time: 200
    		  });
    		});
      }
		$('.my-first').click(function(){
			var page =${page};
			if(page>1){
				$("#hh").val(1);
				$("#listForm").submit();
			}
		});
		$('.prev').click(function(){
			var page =${page};
			if(page>=2){
				$("#hh").val(page-1);
				$("#listForm").submit();
			}
		});
		$('.next').click(function(){
			var page =${page};
			var total=${total};
			if(total>=2){
				$("#hh").val(page+1);
				$("#listForm").submit();
			}
		});
		$('.my-last').click(function(){
			var page =${page};
			var total=${total};
			if(total>=2){
				$("#hh").val(total);
				$("#listForm").submit();
			}
		});
		function myClick(id){
			$.get("/admin/vCode?id="+id,function(data){
				if("error"!=data){
					console.log(data);
					var url ="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+data;
					layer.open({
						  type: 1,
						  title: false,
						  closeBtn: 0,
						  area: ['700px', '450px'],
						  skin: 'layui-layer-nobg', //没有背景色
						  shadeClose: true,
						  content:'<img src='+url+'>'
						});
				}else{
					layer.alert("二维码已经生成过了，请不要多次点击!");	
				}
			}) 
		}
    </script>
    
  </body>

</html>